/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manager.helpers.validation;

import javax.swing.JLabel;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

/**
 *
 * @author diego1
 */
public class FormatedFieldValidationDocument extends PlainDocument {

    FormatedFieldValidator formatedFieldValidator;

    public FormatedFieldValidationDocument(FormatedFieldValidator newFormatedFieldValidator) {
        super();
        this.formatedFieldValidator = newFormatedFieldValidator;
    }

    @Override
    public void insertString(int offset, String str, AttributeSet a)
            throws BadLocationException {
        if (str == null) {
            return;
        }
        if (formatedFieldValidator.isUpper()) {
            str = str.toUpperCase();
        }
        super.insertString(offset, str, a);   // ...aceita str
        formatedFieldValidator.validarCampo();
    }
}
